<!-- <script> {{{ -->
<script setup lang="ts">
import {nextTick, ref} from 'vue'
import {Server} from '@/stores/ajax';
import {ServerUtils} from '@/serverUtils'
import {Delta, QuillEditor} from '@vueup/vue-quill'
import {QuillDeltaToHtmlConverter} from 'quill-delta-to-html';
import {GetUserState} from '@/stores/userState';
import postInputArea from '@/components/bbs/postInputArea1.vue';
import postlist from '@/components/bbs/postList2.vue'
import * as cheerio from 'cheerio'

let user = GetUserState()
let content = $ref<Delta>(new Delta())

const getQuillHTML = (editor: any) => {
    return new QuillDeltaToHtmlConverter(editor.getContents().ops, {}).convert()
}


// let maxPostWordsLength = 150



let forwardVisible = $ref(false)
let forwardEditor = $ref<any>()
const handleForward = (post: any) => {
    if (forwardEditor && post.pid != forwardingPost.pid) forwardEditor.setContents(new Delta())
    forwardingPost = post
    forwardVisible = true
}
let forwardingPost = $ref<any>()
const handleForwardCommit = async () => {
    await Server.post('/post/post', {
        parent_pid: forwardingPost.pid,
        subarea: 10001,
        content: getQuillHTML(forwardEditor)
    }, true).then(res => {
        if (res.data && res.data.code == 0) {
            forwardEditor.setContents(new Delta())
            posts.refresh()
        }
    })
}

const postListCallback = (page: number, posts_per_page: number) => {
    return ServerUtils.getPosts(10001, null, null, ['collect', 'star'], page, posts_per_page, true)
}
const posts = $ref<typeof postlist>()

</script>
<!-- }}} -->

<template>
    <div class="fvs card-block post-main">
        <postInputArea @publish="posts.refresh()"
            :subarea="10001" placeholder="输入内容" />

        <postlist ref='posts'
            :post-callback="postListCallback" />
    </div>


    <!-- <!-1- 转发弹窗 {{{ -1-> -->
    <!-- <el-dialog title="转发" v-model="forwardVisible" -->
    <!--     width="700px" center> -->

    <!--     <div> -->
    <!--         <div class="fh" -->
    <!--             style="justify-content: start;border: grey 2px solid; "> -->
    <!--             <div style="margin:10px 20px;"> -->
    <!--                 <el-avatar :size="50" -->
    <!--                     :src="Server.fileBaseURL + user.avatar" /> -->
    <!--             </div> -->
    <!--             <div class="fv" -->
    <!--                 style="justify-content: start;"> -->
    <!--                 <div style="padding: 5px 0" -->
    <!--                     class="fontsizes3"> -->
    <!--                     <div class="fh" -->
    <!--                         style="justify-content:start;"> -->
    <!--                         <div class="bold1">{{ -->
    <!--                                 user.user_name -->
    <!--                         }}</div>@{{ -->
    <!--     user.user_name -->
    <!-- }} -->
    <!--                     </div> -->
    <!--                 </div> -->
    <!--                 <div class="fontsizes2" -->
    <!--                     style="margin-right: 20px;"> -->
    <!--                     <MyQuill theme="snow" -->
    <!--                         content-type="delta" -->
    <!--                         style="height: 130px;width: 470px;" -->
    <!--                         @ready="(e) => {forwardEditor = e}" /> -->
    <!--                     <!-1- {{ editor?.getText()}} {{ content}} -1-> -->
    <!--                 </div> -->
    <!--                 <div class="fh fontsizes2" -->
    <!--                     style="justify-content: start; gap: 20px; margin: 10px 0;"> -->
    <!--                     <div @click="handleForwardCommit">转发 -->
    <!--                     </div> -->
    <!--                 </div> -->
    <!--             </div> -->
    <!--         </div> -->
    <!--     </div> -->
    <!-- </el-dialog> -->
    <!-- <!-1- }}} -1-> -->

</template>

<style scoped lang="scss">
.ql-bubble .ql-editor {
    padding: 0;
}

.card-block {
    background-color: var(--el-bg-color-overlay);
    box-shadow: var(--el-box-shadow-lighter);
    border-radius: 4px;
}

.post-main {
    flex-basis: 800px;
    min-width: 600px;
    padding: 16px 12px 0;

 }


</style>
<style>
.post-quill {
    height: 100%;
    width: 100%;
}
</style>
